#!/bin/bash
# 安装haproxy keepalived
source comm.cfg

color_text() {
    local color=$1
    local text=$2
    echo -e "\e[${color}m${text}\e[0m"
}

error() {
    color_text "31" "$1"
}

info() {
    color_text "32" "$1"
}

install() {
    apt-get install haproxy keepalived -y
    sed -i "s/nodename/$HOSTNAME/" keepalived.conf
    sed -i "s/ETH/$ETH/g" keepalived.conf
    sed -i "s/SVCVIP/$SVCVIP/" keepalived.conf
    sed -i "s/PGVIP/$PGVIP/" keepalived.conf
    sed -i "s/MYSQLVIP/$MYSQLVIP/" keepalived.conf
    sed -i "s/MAASDOMIND/$MAASDOMIND/" haproxy.cfg
    sed -i "s/N9EDOMIND/$N9EDOMIND/" haproxy.cfg
    sed -i "s/JMSDOMIND/$JMSDOMIND/" haproxy.cfg
    sed -i "s/BACKEND01/$BACKEND01/" haproxy.cfg
    sed -i "s/BACKEND02/$BACKEND02/" haproxy.cfg
    cp haproxy.cfg /etc/haproxy/haproxy.cfg
    cp keepalived.conf /etc/keepalived/keepalived.conf
    systemctl restart haproxy
    systemctl restart keepalived
}

install
